Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ink! e2e-tests #196

Merged
merged 12 commits into from
Feb 26, 2024
Merged

Add ink! e2e-tests #196

merged 12 commits into from
Feb 26, 2024

Conversation

prxgr4mm3r
Copy link
Collaborator

No description provided.

…test generate` command to generate types for mocha tests, add test_helpers for ink_e2e tests, remove generate types from compile, add ink_e2e tests to tamplates
@prxgr4mm3r prxgr4mm3r linked an issue Jan 31, 2024 that may be closed by this pull request
src/templates/contracts/flipper/contract/src/lib.rs.hbs Outdated Show resolved Hide resolved
src/templates/test_helpers/lib.rs.hbs Show resolved Hide resolved
@@ -269,6 +269,15 @@ export class Init extends SwankyCommand<typeof Init> {
runningMessage: "Copying contract template files",
});

this.taskQueue.push({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task needs to be perform only for contractTemplate=psp22

src/commands/contract/test/index.ts Outdated Show resolved Hide resolved
src/commands/contract/test/index.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@ipapandinas ipapandinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to set up the correct testing strategy based on the development dependencies used:

  • ink! end-to-end (E2E) testing for ink! smart contracts.
  • Mocha TypeScript (TS) testing for ask! smart contracts.

Since our current contract templates are for ink! contracts, there is no need to copy TS tests with copyContractTemplateFiles on the init (generate only) command and on the contract new command. Only E2E test helpers are needed for psp22 contracts template.

The tricky part is on the init -c (convert) command when converting an existing project into a Swanky project. Then, we need to first detect the development dependencies used.

However, to be honest, I don't see comprehensive support for ask! in Swanky. The Astar documentation recommends using ink!. Also this issue mention that:

If user choses ink! as a language, tests should be scaffolded using the ink! e2e framework. Using mocha (node.js) is redundant.

@prxgr4mm3r I suggest removing scaffolding for TS tests by default in the following steps:

  1. Refactor copyContractTemplateFiles by removing the test copy.
  2. Refactor copyTestHelpers, renaming it to prepareTestFiles and accepting a "type" argument of type "e2e" or "mocha". On init (generate only) and on the contract new command, it runs as prepareTestFiles("e2e") for psp22 templates.
  3. Preserve the previous folder structure for tests with contract test (no need for a test folder with an index.ts). Preserve the actual optional --mocha flag to run TS tests but perform a generateTypes. Otherwise, E2E tests run by default.
  4. Create a dedicated generate subcommand folder containing 2 commands:
  • generate types (previous TypegenCommand)
  • generate test with contract name argument. By default, it performs prepareTestFiles("e2e") unless an optional template is passed as flag, then it scaffolds TS tests in the selected contract test folder with prepareTestFiles("mocha"). This is similar to the actual test copy in copyContractTemplateFiles. In both cases, if a "tests" folder already exists when running generate test, prompt a warning confirmation to the user.

src/commands/contract/test/index.ts Outdated Show resolved Hide resolved
src/commands/contract/test/index.ts Outdated Show resolved Hide resolved
src/commands/contract/test/generate.ts Outdated Show resolved Hide resolved
src/commands/contract/test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@ipapandinas ipapandinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/commands/contract/compile.ts Outdated Show resolved Hide resolved
src/templates/test_helpers/lib.rs.hbs Outdated Show resolved Hide resolved
src/templates/test_helpers/lib.rs.hbs Show resolved Hide resolved
src/commands/generate/tests.ts Show resolved Hide resolved
@ipapandinas ipapandinas changed the base branch from master to ink-devhub-1 February 26, 2024 12:56
@ipapandinas ipapandinas merged commit 44da31c into ink-devhub-1 Feb 26, 2024
3 checks passed
@ipapandinas ipapandinas deleted the feature/e2e-tests branch February 26, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rust e2e tests for ink contracts
3 participants